package ability

import (
	"fmt"
	"sjy/customcmd/src/constants"
	"sjy/customcmd/src/utils"
)

var VersionInstance = FuncManager.Register(
	&VersionClass{
		FuncObjBase: &FuncObjBase{
			ClassName: constants.Version.Code,
		},
	},
)

type VersionClass struct {
	*FuncObjBase
}

type VersionFile struct {
	Time    string `yaml:"time"`
	Version string `yaml:"version"`
}

func (r *VersionFile) toString() string {
	return fmt.Sprintf("version : %s, time : %s", r.Version, r.Time)
}

func (r *VersionClass) Execute(obj *FuncEntity) {
	var config *VersionFile
	utils.LoadYamlError(constants.VersionFilePath, &config, func(err error) {
		utils.Info("配置文件可能不符合yaml语法！: %v", err)
	})
	if config == nil {
		utils.Info("Version 配置文件丢失。")
	} else {
		utils.Info("%s", config.toString())
	}
	utils.Info("https://gitee.com/mdsSJY/custom-cmd")
}
